%% Author: 77
%% Created: 2011-7-6
%% Description: TODO: Add description to start_vm_cmd
-module(start_vm_cmd).
-author(kanghua ).  
-email(kanghua151@msn.com).  
-date("2011.07.06").  
%%
%% Include files
%%
-include("meta_schema.hrl").
%%
%% Exported Functions
%%
-export([handle/3]).
%%
%% API Functions
%%

handle(Content,From,State) ->
	io:format("handle info ~p ~p ~p ~p ~n",[?MODULE,Content,From,State]), %% debug info
	case check_parm(Content) of 
		 true -> 
			 io:format("check parm pass ~n"),
		     {VmId} = Content,
			 io:format("request info ~p ~n",[VmId]), %% debug info
	         case meta_data_ops:get_vm_runtime_info(VmId) of
				 false ->
					   gen_server:reply(From, {error,vm_not_exist}),  
                       false;
				 Info -> 
					   Node = Info#vm_runtime_info.host_name,
             		   io:format("Node ~p ~n",[Node]), %% debug info
                       case gen_server:call({node_server,list_to_atom(Node)},{start_vm,{VmId}},60000) of
						    {error,Reason} -> 
								gen_server:reploy(From,{errno,vm_start_fail}),
					            false;
							ok -> 
			 					gen_server:reply(From, ok),
                                ok
					   end
              end;
		 false -> 
			 gen_server:reply(From,{error,err_param}),
             false
    end.

%%
%% Local Functions
%%

check_parm(Content)->
	true.
